package org.example;

import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.example.bean.ConsumerComponent;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;

public class ConsumerMainAnno {

    public static void main(String[] args) throws Exception {

        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);

        //获取消费者组件
        ConsumerComponent bean = context.getBean(ConsumerComponent.class);
        while (true) {
            System.in.read();
            for (int i = 0; i < 100; i++) {
                TimeUnit.MILLISECONDS.sleep(9);
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        System.out.println(bean.methodA());
                    }
                }).start();
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        System.out.println(bean.methodB());
                    }
                }).start();
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        System.out.println(bean.methodC());
                    }
                }).start();
            }
        }


    }


    @Configuration
    @PropertySource("classpath:/dubbo-consumer.properties")
    @ComponentScan(basePackages = "org.example.bean")
    @EnableDubbo
    static class ConsumerConfiguration {
    }


}
